/*
 * 创建日期 2009-12-14
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.bean;

import  org.fantasy.common.db.bean.ReportRow;
import  org.fantasy.common.grid.report.ReportDataParser;
import  org.fantasy.common.util.StringUtil;

import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONObject;


/**
 *  报表参数
 * @author: 王文成
 * @version: 1.0
 * @since 2009-12-14
 */
public class ReportExportParam extends ReportTagParam{
    
    private List<ReportRow> resultList;
    
    public ReportExportParam(String jsonText ) throws Exception{
        initParams( jsonText );
    }
    
    /**
     * 初始化参数
     * @throws Exception
     */
    public void initParams(String jsonText) throws Exception{
        JSONObject obj = JSONObject.fromObject(jsonText);
        Iterator iter = obj.keys();
        Class thisClass = this.getClass();
        while( iter.hasNext() ){
            String name = (String)iter.next();
            String methodName = "set" + StringUtil.firstCharUpperCase(name);
            Method method = thisClass.getMethod(methodName,new Class[]{String.class});
            method.invoke(this,obj.getString(name));
        }
    }
    
    @Override
    protected List<ReportRow> formatDataList() throws Exception {
        if( REPORT_TYPE_STAT.equals(reportType) ){
            ReportDataParser parser = new ReportDataParser();
            parser.setDataList(resultList);
            parser.setStatCols(getStatColsList());
            parser.setSumCols(getSumColsList());
            parser.setSumTotal(isSumTotal());
            parser.setSubTotal(isSubTotal());
            parser.parse();
            return parser.getResultList();
        }
        return resultList;
    }
    
    public void setResultList( List<ReportRow> resultList) {
        this.resultList = resultList;
    }
}